home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / examples / exec / lists.c next >
C/C++ Source or Header  |  1996-07-15  |  3KB  |  131 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     lists.c
  5.  
  6.     DESCRIPTION
  7.     This file contains a complete ready-to-compile example of how to
  8.     use lists.
  9.  
  10.     NOTES
  11.  
  12.     BUGS
  13.  
  14.     TODO
  15.  
  16.     EXAMPLES
  17.  
  18.     SEE ALSO
  19.  
  20.     INDEX
  21.  
  22.     HISTORY
  23.     30-08-95    digulla created
  24.  
  25. ******************************************************************************/
  26.  
  27. /**************************************
  28.         Includes
  29. **************************************/
  30. /* This define is to enable certain features that the original AmigaOS
  31.     lacks. The example will compile if you comment this one out so
  32.     you can see what the advantage really is :) */
  33. #define AOS_ALMOST_COMPATIBLE
  34.  
  35. /* All neccessary #include's for the example */
  36. #include <exec/lists.h>
  37. #include <clib/exec_protos.h>
  38.  
  39. /* These are #include's neccessary to compile but not for the example
  40.     itself */
  41.  
  42.  
  43. /**************************************
  44.            Local Types
  45. **************************************/
  46. /* Example 1: How to use the struct List in other structures */
  47. typedef struct _DemoList
  48. {
  49.     struct List dl_List;    /* Here we collect all the nodes.
  50.                     There is no rule that this has
  51.                     to be the first thing in the
  52.                     new type, but it has advantages
  53.                     (see below).                    */
  54.     UBYTE     * dl_Name;    /* The name of our list         */
  55. } DemoList;
  56.  
  57. /* Example 2: How to make use of the Node-structure */
  58. typedef struct _DemoNode
  59. {
  60.     struct Node dn_Node;    /* This should be the first thing
  61.                     in any node !            */
  62.     UBYTE    dn_Name[32];    /* Nodes just store a pointer to
  63.                     the name, but I want it in the
  64.                     node itself.            */
  65. } DemoNode;
  66.  
  67.  
  68. /**************************************
  69.         Functions
  70. **************************************/
  71.  
  72.  
  73. /*****************************************************************************
  74.  
  75.     NAME */
  76.     int main (
  77.  
  78. /*  SYNOPSIS */
  79.     int    argc,
  80.     char ** argv)
  81.  
  82. /*  FUNCTION
  83.     This is the main routine for the example on how to use
  84.     nodes.
  85.  
  86.     INPUTS
  87.     None... we ignore them.
  88.  
  89.     RESULT
  90.     Always 0.
  91.  
  92.     NOTES
  93.  
  94.     BUGS
  95.  
  96.     SEE ALSO
  97.  
  98.     INTERNALS
  99.  
  100.     HISTORY
  101.     30-08-95    digulla created
  102.  
  103. ******************************************************************************/
  104. {
  105.     /* First we need some variables to work with. Since this demo
  106.     should show how to use lists and nodes, I do not use
  107.     dynamic allocated memory. */
  108.     DemoList list;
  109.     DemoNode nodes[10];
  110.  
  111.     /* Before we can use a list, we have to intialize it. Since we
  112.     have put the List-struct at the top if out new type, we
  113.     can give the address of the variable and need not look into
  114.     it (ie. no &list.nl_List) but we need a cast. */
  115. #ifdef AOS_ALMOST_COMPATIBLE
  116.     NewList (&list);
  117. #else
  118. #   ifdef USE_CAST
  119.     NewList ((struct List *)&list);
  120. #   else /* No cast */
  121.     NewList (&list.dl_List);
  122. #   endif
  123. #endif
  124.  
  125. } /* main */
  126.  
  127.  
  128. /******************************************************************************
  129. *****  ENDE lists.c
  130. ******************************************************************************/
  131.